<?php
namespace app\admin\controller;
use think\Controller;
use think\Request; 
use \think\db;
class Base extends Controller
{

    protected static $tb = [
      'shop'    => 'shop',
      'user'    => 'user',
      'member'    => 'member',
      'order'    => 'order',
      'sys_user'    => 'sys_user',
      'sys_role'    => 'sys_role',
      'sys_permission'    => 'sys_permission',
      'sys_role_permission'    => 'sys_role_permission',
      'area'    => 'area',
      
    ];
    
      protected $data = [];
      
      public function _initialize() {
        $request= Request::instance();
        header("Access-Control-Allow-Origin:*");
        header('Content-Type:application/json;charset=utf8');
        header("Access-Control-Allow-Headers: Origin, X-Requested- With, Content-Type, Accept");
        //获取前端传过来得参数
        $this->data = Request::instance()->param();   
        //权限检测
        $user = session("user_id"); 
        if(!$user){
          //登录页面
          $this->redirect("login/index");
        }else{
          $addr_list = get_cache("user_".$user['id']); 
          $addr = $request->module()."/".$request->controller()."/".$request->action();
          // dump($addr);
          // exit;
          if($addr_list){
            if (!in_array($addr, array_values($addr_list))){
                 echo "您没有权限操作";
                 exit; 
            }  
          }else{
            echo "您没有权限操作";
            exit; 
          }
        }
     
      }
    
}